//
//  PayFooter.m
//  夺宝吧
//
//  Created by xiaocai on 15/6/29.
//  Copyright (c) 2015年 FangYuan. All rights reserved.
//

#import "PayFooter.h"
#import "PayedVC.h"
#import "MyDuoBaoVC.h"
#import "PayForDbbVC.h"
#import "WYZfbPay.h"
#import "JDWebPayVC.h"
//update by weienjie 20150918
#import "Iapppay.h"
#import "ShoppingCarVC.h"
#import "ChongZhiController.h"

//end weienjie

@interface PayFooter ()<UIAlertViewDelegate>
{
    //积分选项
    __weak IBOutlet UIButton *jifenBtn;
    //夺币选项
    __weak IBOutlet UIButton *duobiBtn;
    //支付宝选项
    __weak IBOutlet UIButton *zfbBtn;
    //京东支付选项
    __weak IBOutlet UIButton *jdzfBtn;
    //微信支付
    __weak IBOutlet UIButton *wxzfBtn;
    //爱贝 微信支付选项
    __weak IBOutlet UIButton *iapWXBtn;
    
    //end by weienjie
    
    //总个数
    __weak IBOutlet UILabel *payLab;
    //钱
    
    __weak IBOutlet UILabel *moneyLab;
    
    __weak IBOutlet UIView *whiteView;
    __weak IBOutlet UIView *grayView;
    
    //夺币
    __weak IBOutlet UILabel *duobilab;
    __weak IBOutlet UILabel *myDuobiLab;
    
    //积分
    __weak IBOutlet UILabel *jifenLab;
    __weak IBOutlet UILabel *myJifenLab;
    
    //透明按钮
    __weak IBOutlet UIButton *tmlBtn;
    __weak IBOutlet UIButton *tjfBtn;
    __weak IBOutlet UIButton *tzfbBtn;
    __weak IBOutlet UIButton *tjdBtn;
    __weak IBOutlet UIButton *twxBtn;
    __weak IBOutlet UIButton *iapppayWXBtn;
    
    
    __weak IBOutlet UIImageView *zfbimg;
    __weak IBOutlet UIImageView *jdimg;
    
    __weak IBOutlet UIImageView *wximg;
    
    __weak IBOutlet UILabel *tsLab;

    UILabel *zhegai;
    
    //结果界面
    PayedVC *_payedVC;
    //装选项的数组
    NSArray *_btns;
    
    __weak IBOutlet UILabel *zhbLabel;
    __weak IBOutlet UILabel *zhbdesLabel;
    __weak IBOutlet UILabel *jdLabel;
    __weak IBOutlet UILabel *jddesLabel;
    __weak IBOutlet UILabel *wxLabel;
    __weak IBOutlet UILabel *wxdesLabel;
    
    
    UIView *line1;
    
    UIView *line2;
    
    
    __weak IBOutlet UIView *explainView;
    
    
    __weak IBOutlet UIImageView *iappayAapImage;
    __weak IBOutlet UILabel *iapppayLabel;
    __weak IBOutlet UILabel *iapppayDetailLabel;
    
    CGRect zfFrame;
    CGRect jdFrame;
    CGRect iapwxFrame;
    CGRect iapzfFrame;
    
}

@property (nonatomic , strong) UIButton *selectedBtn;

@end
@implementation PayFooter
- (void)awakeFromNib
{
    
    if (WYMWITH > 320) {
        tsLab.font = [UIFont systemFontOfSize:15];
    }
    // update by weienjie 20150918
    
    //这里的顺序很重要 透明按钮
    _btns = @[jifenBtn,duobiBtn,zfbBtn,jdzfBtn,wxzfBtn,iapWXBtn];
    
    self.backgroundColor = QBB_GRAY_COLOR;
    
  
    
    //设置支付旁边按钮的被选中时的状态和添加时间
    for (UIButton *btn in _btns) {
        [btn setImage:[UIImage imageNamed:@"icon_checkbox_press"] forState:UIControlStateSelected];
        [btn
         addTarget:self action:@selector(btnOnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
   

    [[IapppayKit sharedInstance] setAppId:mOrderUtilsAppId mACID:mOrderUtilsChannel];
    
    [self layoutSubviews];
    
    [self storeFrame];
    
   
}

- (void)setLineView{
    
    [whiteView addSubview:[WYPublic getFenGexian:0 :0 :WYMWITH :0.5]];
    //    [whiteView addSubview:[WYPublic getFenGexian:0 :whiteView.frame.size.height :WYMWITH :0.5]];
    //中间灰色部分的线
    [grayView addSubview:[WYPublic getFenGexian:0 :0 :WYMWITH :0.5]];
//    [grayView addSubview:[WYPublic getFenGexian:0 :grayView.frame.size.height :WYMWITH :0.5]];
    
    
//    UIView *zfViewBottonLine  = [WYPublic getLineView:0 orginY:self.zfView.frame.size.height sizeWidth:WYMWITH sizeHeight:0.5];
//    [self.zfView addSubview:zfViewBottonLine];
//    [self.zfView bringSubviewToFront:zfViewBottonLine];
    //中间支付宝 微信等3条线
    [self.zfView addSubview:[WYPublic getLineView:0 orginY:0 sizeWidth:WYMWITH sizeHeight:0.5]];
    [self.iapAliView addSubview:[WYPublic getLineView:0 orginY:0 sizeWidth:WYMWITH sizeHeight:0.5]];
    [self.jdView addSubview:[WYPublic getLineView:0 orginY:0 sizeWidth:WYMWITH sizeHeight:0.5]];
    [self.iapWxView addSubview:[WYPublic getLineView:0 orginY:0 sizeWidth:WYMWITH sizeHeight:0.5]];


    //
    [whiteView addSubview:[WYPublic getLineView:0 orginY:CGRectGetMaxY(tmlBtn.frame) sizeWidth:WYMWITH sizeHeight:0.5]];
}


//设置默认值
- (void)setDefaultPay{
    UserInfo *user = [[UserInfo alloc]init];
    if ((_allPrice <= user.user_money.integerValue)){
        [self cleanBtnsOnClick:tmlBtn];
        return;
    }

    if ((_allPrice *100 <= user.user_jifen.integerValue)){
        [self cleanBtnsOnClick:tjfBtn];
        return;
    }
    
    if (self.zfbflag){
        [self cleanBtnsOnClick:tzfbBtn];
        return;
    }
    if (self.iapppayFlagAlipay){
        [self cleanBtnsOnClick:iapppayWXBtn];
        return;
    }
    if (self.iapppayflag){
        [self cleanBtnsOnClick:twxBtn];
        return;
    }
    
    if (self.jdflag){
        [self cleanBtnsOnClick:tjdBtn];
        return;
    }
    
}

- (void)storeFrame{
    zfFrame = self.zfView.frame;
    jdFrame = self.jdView.frame;
    iapwxFrame = self.iapWxView.frame;
    iapzfFrame = self.iapAliView.frame;
    
}
//小按钮的点击事件
- (void)btnOnClick:(UIButton *)sender
{
    //判断是否可选夺宝币支付
    if (sender == duobiBtn) {
        if ([self ifDuobiCanSelect] == NO) {
            return;
        }
    }
    //判断是否可选积分支付
    if (sender == jifenBtn) {
        if ([self ifJiFenCanSelect] == NO) {
            return;
        }
    }
    
    for (UIButton *btn in _btns) {
        btn.selected = NO;
    }
    
    sender.selected = YES;
    self.selectedBtn = sender;
    
    [self changeColor];
}
//支付选项透明按钮的监听事件
- (IBAction)cleanBtnsOnClick:(UIButton *)sender {
    if (sender == tmlBtn) {
        if ([self ifDuobiCanSelect] == NO) {
            return;
        }
    }
    if (sender == tjfBtn) {
        if ([self ifJiFenCanSelect] == NO) {
            return;
        }
    }
    //改变支付选项中旁边的选中按钮
    for (UIButton *btn in _btns) {
        btn.selected = NO;
    }
    UIButton *seletBtn = _btns[sender.tag - 1];
    seletBtn.selected = YES;
    [self changeColor];
}

//判断是否可选夺币
- (BOOL)ifDuobiCanSelect
{
       UserInfo *user = [[UserInfo alloc]init];
    
    
    if (_allPrice > [user.user_money integerValue]) {
        UIAlertView *alt = [[UIAlertView alloc]initWithTitle:@"温馨提示：" message:@"您的夺币不足，快去充值吧" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"去充值", nil];
        [alt show];
        return NO;
    }
        return YES;
}
//判断是否可选积分
- (BOOL)ifJiFenCanSelect
{
   
    UserInfo *user = [[UserInfo alloc]init];
    if (_allPrice*100 > [user.user_jifen integerValue]) {
        [WYPublic showMessageWithTitle:@"温馨提示：" Msg:@"您的积分不足"];
        return NO;
    }
    return YES;
}
//改变高亮
- (void)changeColor
{
    //夺宝币
    if (duobiBtn.selected == YES) {
        duobilab.textColor = [UIColor blackColor];
        myDuobiLab.textColor = [UIColor blackColor];
    }else{
        duobilab.textColor = [UIColor grayColor];
        myDuobiLab.textColor = [UIColor grayColor];
    }
    //积分btn
    if (jifenBtn.selected == YES) {
        jifenLab.textColor = [UIColor blackColor];
        myJifenLab.textColor = [UIColor blackColor];
        
    }else{
        jifenLab.textColor = [UIColor grayColor];
        myJifenLab.textColor = [UIColor grayColor];
    }
    
    
    if (jifenBtn.selected || duobiBtn.selected) {
        payLab.hidden = NO;
        moneyLab.hidden = YES;
    }else{
        payLab.hidden = YES;
        
        //上架前处理
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        NSNumber *flag = [user objectForKey:@"user_show_pay"];
        if ([flag intValue] == 1) {
            moneyLab.hidden = NO;
        }
        
    }
    [self changeColorWithCount:_allPrice];
}
- (void)changeColorWithCount:(NSInteger)count
{
    payLab.attributedText = [WYPublic getRedMiddleStrWithLeft:@"总需支付:" Middle:[NSString stringWithFormat:@"%ld",(unsigned long)count] RightStr:@"夺币" Font:14];
    moneyLab.attributedText = [WYPublic getRedMiddleStrWithLeft:@"总需支付:" Middle:[NSString stringWithFormat:@"￥%ld",(unsigned long)count] RightStr:@"" Font:14];
    
    UserInfo *user = [[UserInfo alloc]init];
    
    myDuobiLab.attributedText = [WYPublic getRedMiddleStrWithLeft:@"(您的夺币:" Middle:user.user_money RightStr:@")" Font:14];
    if ([user.user_money integerValue] >= count) {
        duobilab.attributedText = [WYPublic getRedMiddleStrWithLeft:@"支付:" Middle:[NSString stringWithFormat:@"%ld",(unsigned long)count] RightStr:@"夺币" Font:14];
    }else{
        duobilab.attributedText = [WYPublic getRedMiddleStrWithLeft:@"支付:" Middle:[NSString stringWithFormat:@"%ld",(unsigned long)count] RightStr:@"夺币(夺币不足)" Font:14];
    }
   
    myJifenLab.attributedText = [WYPublic getRedMiddleStrWithLeft:@"(您的积分:" Middle:user.user_jifen RightStr:@",100积分=1夺币)" Font:14];
    if([user.user_jifen integerValue] >= count*100){
        jifenLab.attributedText = [WYPublic getRedMiddleStrWithLeft:@"支付:" Middle:[NSString stringWithFormat:@"%ld",(unsigned long)count*100] RightStr:@"积分" Font:14];
    }else{
        jifenLab.attributedText = [WYPublic getRedMiddleStrWithLeft:@"支付:" Middle:[NSString stringWithFormat:@"%ld",(unsigned long)count*100] RightStr:@"积分(积分不足)" Font:14];
    }
}
- (void)setAllPrice:(NSInteger)allPrice
{
    _allPrice = allPrice;
    [self changeColorWithCount:allPrice];
    
    //改变默认选项
    UserInfo *user = [[UserInfo alloc]init];
    if (_allPrice <= [user.user_money integerValue]) {
        duobiBtn.selected = YES;
    }else if (_allPrice*100 <= [user.user_jifen integerValue]){
        jifenBtn.selected = YES;
    }else{
        zfbBtn.selected = YES;
    }
    
    [self changeColor];
}

//支付前验证
- (void)payYanzheng
{
    //上架前处理
    //上架前处理
    //上架前处理
    //上架前处理
    //上架前处理
//    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
//    NSNumber *flag = [user objectForKey:@"user_show_pay"];
//    if ([flag intValue] == 0 && (zfbBtn.selected || jdzfBtn.selected)) {
//        if(duobiBtn.selected == NO && jifenBtn.selected == NO){
//            [WYPublic showMessageWithTitle:nil Msg:@"您的夺币和积分不足"];
//        }
//        return;
//    }
    _payedVC = [[PayedVC alloc]init];
    _payedVC.money = [NSString stringWithFormat:@"%ld",(unsigned long)_allPrice];
    [[WYMainTabBarVC shareMainTaBarVC].navigationController pushViewController:_payedVC animated:YES];
    
    //默认夺币支付
    NSString *payStyle = nil;
    if (duobiBtn.selected){
        payStyle = @"money";
    }
    //积分支付
    if (jifenBtn.selected) {
        payStyle = @"score";
    }
    //支付宝支付
    else if(zfbBtn.selected){
        payStyle = @"alipay_mobile";
    }
    //京东网银支付
    else if(jdzfBtn.selected){
        payStyle = @"pingpp";
    }
    //爱贝微信支付
    else if(wxzfBtn.selected){
        payStyle = @"iapppay";
    }
    //爱贝支付宝
    else if (iapWXBtn.selected){
        payStyle = @"iapppay";
    }
    if (payStyle == nil || payStyle.length == 0){
        [WYPublic showErrorWithTitle:nil Msg:@"你没有选择支付方式!"];
        return;
    }
    

    NSDictionary *params = @{@"id":self.orderId,@"pay_type":payStyle,@"uid":[UserInfo getUserID],@"token":[UserInfo getUserToken],@"refresh_token":[UserInfo getRefreshToken]};
    [WYRequest startPostForDicWithUrlStR:[NSString stringWithFormat:@"%@%@",DBB_IP,YANZHENG_URL] Parameters:params successBlock:^(NSDictionary *dic) {
        
        NSNumber *ret = dic[@"ret"];
        if ([ret intValue] == 0) {
            /*******************
             *积分或者夺币支付
             ***************************/
            if(jifenBtn.selected||duobiBtn.selected){
                //延时三秒
                double delayInSeconds = 1.0;
                dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
                dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                    if ([[WYPublic GetCurrentviewController] class] == [PayedVC class]) {
                        //支付成功后刷新购物车
                        [ShoppingCarVC shareShoppingCarVC].firstFlag = YES;
                        //跳往支付结果界面刷新结果
                        _payedVC.rltType = PdcSuccess;
                        [_payedVC updateViews];
                    }
                });
            }else{
                //第三方支付
               [self pay];
            }
            
        }
        else{
            [WYPublic showMessageWithTitle:@"订单验证失败:" Msg:dic[@"msg"]];
            //取消订单
            [self.father cancelOrder];
            //延时三秒
            double delayInSeconds = 3.0;
            dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
            dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                if ([[WYPublic GetCurrentviewController] class] == [PayedVC class]) {
                    //跳往支付结果界面刷新结果
                    _payedVC.rltType = PdcFailed;
                    [_payedVC updateViews];
                    
                }
            });
        }
    } failedBlock:^{
        //延时三秒
        double delayInSeconds = 3.0;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            if ([[WYPublic GetCurrentviewController] class] == [PayedVC class]) {
                //跳往支付结果界面刷新结果
                _payedVC.rltType = PdcFailed;
                [_payedVC updateViews];
            }
        });

    } needLog:NO];
}
//支付
- (void)pay{
    /********************
     *三方支付
     ************************/
    //支付宝支付
    if (zfbBtn.selected) {
        WYZfbPay *zfbPay = [[WYZfbPay alloc]init];
        zfbPay.payModel = self.zfbModel;
        AppDelegate *app = [UIApplication sharedApplication].delegate;
        app.zfbPay = zfbPay;
        [zfbPay zfbPayWithOrderNum:self.paycode OrderId:self.orderId PdcTitle:self.zfbModel.goods_name PdcDesc:[NSString stringWithFormat:@"%@_%@",@"iOS端支付",self.paycode] Price:[NSString stringWithFormat:@"%ld",(unsigned long)_allPrice]];
    }
//    else if (jdzfBtn.selected){
//        JDWebPayVC *jdvc = [[JDWebPayVC alloc]init];
//        jdvc.mtitle = @"支付页面";
//        jdvc.money =[NSString stringWithFormat:@"%ld",(unsigned long)_allPrice];
//        jdvc.urlStr = [NSString stringWithFormat:@"%@api/ApiPay/pay?uid=%@&token=%@&id=%@&pay_type=pingpp&sub_pay_type=jdpay_wap",DBB_IP,[UserInfo getUserID],[UserInfo getUserToken],self.orderId];
//        [[WYMainTabBarVC shareMainTaBarVC].navigationController pushViewController:jdvc animated:YES];
//    }
    //update by weienie 20150918
    //爱贝微信支付
    if (wxzfBtn.selected) {
        Iapppay *iappay = [[Iapppay alloc] initWithPayModel:self.iapppayWXModel];
        [iappay iappayWithOrderId:self.paycode price:[NSString stringWithFormat:@"%ld",(unsigned long)_allPrice] privateInfo:[NSString stringWithFormat:@"%@_%@",@"iOS端支付",self.paycode] wareName:self.iapppayWXModel.goods_name];
//         - (void)iappayWithOrderId:(NSString *)orderId price:(NSString *)pirce privateInfo:(NSString *)info wareName:(NSString*)waresName
    }
    
    //爱贝支付宝
    if (iapWXBtn.selected){
        Iapppay *iappay = [[Iapppay alloc] initWithPayModel:self.iapppayzfbModel];
        [iappay iappayWithOrderId:self.paycode price:[NSString stringWithFormat:@"%ld",(unsigned long)_allPrice] privateInfo:[NSString stringWithFormat:@"%@_%@",@"iOS端支付",self.paycode] wareName:self.iapppayzfbModel.goods_name];
    }
    //update end weienjie

}
//支付按钮点击激活的方法//支付按钮点击激活的方法//支付按钮点击激活的方法
//支付按钮点击激活的方法//支付按钮点击激活的方法//支付按钮点击激活的方法
//支付按钮点击激活的方法//支付按钮点击激活的方法//支付按钮点击激活的方法
//支付按钮点击激活的方法//支付按钮点击激活的方法//支付按钮点击激活的方法
- (void)payBtnOnClick
{
    //京东网银支付没问题
    if (jdzfBtn.selected){
        JDWebPayVC *jdvc = [[JDWebPayVC alloc]init];
        jdvc.mtitle = @"支付页面";
        jdvc.money = [NSString stringWithFormat:@"%ld",(unsigned long)_allPrice];
        jdvc.urlStr = [NSString stringWithFormat:@"%@api/ApiPay/pay?uid=%@&token=%@&id=%@&pay_type=pingpp&sub_pay_type=jdpay_wap",DBB_IP,[UserInfo getUserID],[UserInfo getUserToken],self.orderId];
        [[WYMainTabBarVC shareMainTaBarVC].navigationController pushViewController:jdvc animated:YES];
        return;
    }
    //支付宝 爱贝支付宝 爱贝微信
    [self payYanzheng];
}


- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        //跳往充值页面
        [self goToPay];
    }
}
////跳往充值页面
//- (void)goToPay
//{
//    [WYPublic addZheZhaoToWindowWithTitle:nil];
//    NSDictionary *params = @{@"uid":[UserInfo getUserID],@"token":[UserInfo getUserToken],@"refresh_token":[UserInfo getRefreshToken]};
//    [WYRequest startPostForDicWithUrlStR:[NSString stringWithFormat:@"%@%@",DBB_IP,PEIZHI_URL] Parameters:params successBlock:^(NSDictionary *dic) {
//        NSNumber *ret = dic[@"ret"];
//        if (ret.intValue == 0) {
//            
//            PayForDbbVC *payDbbVC = [[PayForDbbVC alloc]init];
//            payDbbVC.peizhiDic = dic[@"data"];
//            [[WYMainTabBarVC shareMainTaBarVC].navigationController pushViewController:payDbbVC animated:YES];
//        }else{
//            if(ret.intValue>2000 && ret.intValue < 3000){
//                //用户过期，强制重新登录 先删除用户信息
//                [UserInfo deleteUserInfo];
//                //登录
//                [WYPublic ifUserHaveLogin];
//                [WYPublic showMessageWithTitle:@"提示：" Msg:@"登录信息已过期"];
//            }
//            
//        }
//        [WYPublic removeZheZhaoToWindow];
//    } failedBlock:^{
//        [WYPublic removeZheZhaoToWindow];
//    } needLog:NO];
//}
//跳往充值页面

- (void)goToPay
{
    [WYPublic addZheZhaoToWindowWithTitle:nil];
    NSDictionary *params = @{@"uid":[UserInfo getUserID],@"token":[UserInfo getUserToken],@"refresh_token":[UserInfo getRefreshToken]};
    [WYRequest startPostForDicWithUrlStR:[NSString stringWithFormat:@"%@%@",DBB_IP,PEIZHI_URL] Parameters:params successBlock:^(NSDictionary *dic) {
        NSNumber *ret = dic[@"ret"];
        if (ret.intValue == 0) {
            //            PayForDbbVC *payDbbVC = [[PayForDbbVC alloc]init];
            //            payDbbVC.peizhiDic = dic[@"data"];
            //            [[WYMainTabBarVC shareMainTaBarVC].navigationController pushViewController:payDbbVC animated:YES];
            NSInteger is_alipay_mobile = 1;
            NSInteger is_iapppay_wx = 1;
            NSInteger is_iapppay_zf = 1;
            NSInteger is_pingpp_jd = 1;
            NSDictionary *data = dic[@"data"];
            //判断支付宝是否可用
            id available = data[@"valid_pays"][@"alipay_mobile"][@"available"];
            if ( [available class] != [NSNull class]){
                is_alipay_mobile = [(NSNumber*)available integerValue];
            }else{
                is_alipay_mobile = 0;
            }
            
            //判断iapppay微信是否可用
            available =data[@"valid_pays"][@"iapppay"][@"available"];
            if ( [available class] != [NSNull class]){
                is_iapppay_wx = [(NSNumber*)available integerValue];
            }else{
                is_iapppay_wx = 0;
            }
            
            //判断iapppay支付宝是否可用
            available =data[@"valid_pays"][@"iapppay_alipay"][@"available"];
            if ( [available class] != [NSNull class]){
                is_iapppay_zf = [(NSNumber*)available integerValue];
            }else{
                is_iapppay_zf = 0;
            }
            
            //判断pingpp京东支付是否可用
            available =data[@"valid_pays"][@"pingpp"][@"available"];
            if ( [available class] != [NSNull class]){
                is_pingpp_jd = [(NSNumber*)available integerValue];
            }else{
                is_pingpp_jd = 0;
            }
            
            
            ChongZhiController *chongZhiVC = [[ChongZhiController alloc]init];
            chongZhiVC.peizhiDic = dic[@"data"];
            //将是否支付可用的传递给chongZhiVC
            chongZhiVC.is_alipay_mobile = is_alipay_mobile;
            chongZhiVC.is_iapppay_wx  = is_iapppay_wx;
            chongZhiVC.is_iapppay_zfb = is_iapppay_zf;
            chongZhiVC.is_pingpp_jd  = is_pingpp_jd;
            //将支付模型传入chongZhiVC
            [self setInitChongZhiInfoIntoChongZhiController:chongZhiVC dict:dic];
            //获取主tabar的navigationController push充值控制器
            [[WYMainTabBarVC shareMainTaBarVC].navigationController pushViewController:chongZhiVC animated:YES];
            
        }else{
            if(ret.intValue>2000 && ret.intValue < 3000){
                //用户过期，强制重新登录 先删除用户信息
                [UserInfo deleteUserInfo];
                //登录
                [WYPublic ifUserHaveLogin];
                [WYPublic showMessageWithTitle:@"提示：" Msg:@"登录信息已过期"];
            }
            
        }
        [WYPublic removeZheZhaoToWindow];
    } failedBlock:^{
        [WYPublic removeZheZhaoToWindow];
    } needLog:NO];
}

//将获取到的充值模型转导充值控制器中
//此处的dic是原生的dic 需要手动将其他的数据剥离s
- (void)setInitChongZhiInfoIntoChongZhiController:(ChongZhiController*)chongZhiVC dict:(NSDictionary*)dic{
    //支付宝支付模型
    PayInfoModel *zfbPayModel = [[PayInfoModel alloc]init];
    NSDictionary *dict1 = dic[@"data"][@"valid_pays"][@"alipay_mobile"][@"pay_info"];
    if (![dict1 isKindOfClass:[NSNull class]]){
        [zfbPayModel setValuesForKeysWithDictionary:dict1];
    }
    //爱贝微信支付模型
    PayInfoModel *iapppayWXPayModel = [[PayInfoModel alloc]init];
    NSDictionary *dict2 = dic[@"data"][@"valid_pays"][@"iapppay"][@"pay_info"];
    if (![dict2 isKindOfClass:[NSNull class]]){
        [iapppayWXPayModel setValuesForKeysWithDictionary:dict2];
    }
    //爱贝微信支付模型
    PayInfoModel *iapppayzfbPayModel = [[PayInfoModel alloc]init];
    NSDictionary *dict3 = dic[@"data"][@"valid_pays"][@"iapppay_alipay"][@"pay_info"];
    if (![dict3 isKindOfClass:[NSNull class]]){
        [iapppayzfbPayModel setValuesForKeysWithDictionary:dict3];
    }
    //pingpp京东支付模型
    PayInfoModel *pingppJDPayModel = [[PayInfoModel alloc]init];
    NSDictionary *dict4 = dic[@"data"][@"valid_pays"][@"pingpp"][@"pay_info"];
    if (![dict4 isKindOfClass:[NSNull class]]){
        [pingppJDPayModel setValuesForKeysWithDictionary:dict4];
    }
    
    chongZhiVC.zfbModel = zfbPayModel;
    chongZhiVC.iapppayWXModel = iapppayWXPayModel;
    chongZhiVC.iapppayzfbModel = iapppayzfbPayModel;
    chongZhiVC.pingppJDModel = pingppJDPayModel;
    
}

//调整支付宝坐标
- (void)changeZFB
{
    NSLog(@"%@",NSSTRING_PRETTY_FUNCTION);
    NSString *str = NSSTRING_PRETTY_FUNCTION;
    if (self.zfbflag == 0){
        //隐藏支付宝

        self.zfView.hidden = YES;
        self.zfbflag = 0;
    }
    
}

//爱贝支付宝
- (void)changeIAPPPayAlipay{
    
    //如果爱贝支付宝需要
    if (self.iapppayFlagAlipay == 0){
        
        self.iapAliView.hidden = YES;
        self.iapppayFlagAlipay =  0;
    }
    
    if (self.iapppayFlagAlipay != 0 && (self.zfbflag == 0)){
        //与支付宝换位置
        self.iapAliView.frame = zfFrame;
        
        self.zfbflag = 1;//说明支付宝的位置已经有人了
        self.iapppayFlagAlipay = 0;  //爱贝支付宝的位置没人
        return;
    }
    
    
}


//调整京东支付坐标
- (void)changeJD
{
    
    if (self.jdflag == 0){
        self.jdView.hidden = YES;
    }
    
    if ((self.jdflag != 0) && (self.zfbflag == 0 )){
        //与支付宝换位置
        
        self.jdView.frame = zfFrame;
        
        self.zfbflag = 1;       //支付宝位置有人
        self.jdflag = 0;         //京东无人
        
        return;
    }
    
    if ((self.jdflag !=0 )&&( self.iapppayFlagAlipay == 0)){
        //与爱贝支付宝换位置
        
        self.jdView.frame = iapzfFrame;
        

        self.iapppayFlagAlipay = 1; // 爱贝支付宝有人
        self.jdflag = 0;           //京东无人
        return;
    }
    
}
//update by weienjie 20150918
//调整微信支付坐标
- (void)changeIAPPPay
{
    
    if ((self.iapppayflag == 0)){
        
        self.iapWxView.hidden = YES;
        self.iapppayflag = 0;
    }
    
    if ((self.iapppayflag != 0 )&& (self.zfbflag == 0)){
        //调到支付宝的位置
        
        self.iapWxView.frame = zfFrame;
        
        self.zfbflag = 1; //支付宝位置有人
        self.iapppayflag = 0; //位置空缺
        return;
    }
    
    if ((self.iapppayflag != 0) && (self.iapppayFlagAlipay == 0)){
        //调到爱贝支付宝的位置
        
        
        self.iapWxView.frame = iapzfFrame;
        
        self.iapppayFlagAlipay = 1;  //爱贝支付宝有人
        self.iapppayflag = 0 ;   //爱贝微信没人
        return;
        
    }
    if ((self.iapppayflag != 0) && (self.jdflag == 0)){
        //与京东支付换位置
        
        self.iapWxView.frame = jdFrame;
        
        self.jdflag = 1;
        self.iapppayflag = 0;
        return;
    }

    
}


-(void)changeFrame{
    CGRect newFrame = explainView.frame;

    explainView.frame = CGRectMake(newFrame.origin.x, newFrame.origin.y - 50  , newFrame.size.width, newFrame.size.height +50 );
//
}

//如果都没有
- (void)ifNoAll
{
    if (jifenBtn.selected == NO && duobiBtn.selected == NO) {
        if (!zfbBtn.hidden) {
            zfbBtn.selected = YES;
        }
        else if (!jdzfBtn.hidden)
        {
            jdzfBtn.selected = YES;
        }
        else if (!wxzfBtn.hidden)
        {
            wxzfBtn.selected = YES;
        }
    }

    if (!line1) {
//        line1 = [WYPublic getFenGexian:0 :tzfbBtn.frame.origin.y+CGRectGetHeight(tzfbBtn.frame) :WYMWITH :0.5];
//        [whiteView addSubview:line1];
    }
    if (!line2) {
//        line2 = [WYPublic getFenGexian:0 :tjdBtn.frame.origin.y+CGRectGetHeight(tjdBtn.frame) :WYMWITH :0.5];
//        [whiteView addSubview:line2];
    }

    CGFloat height = 0;
    if (!zfbimg.hidden && !jdimg.hidden && !wximg.hidden) {
        height = 0;
        [line1 setHidden:NO];
        [line2 setHidden:NO];
    }
    else if (!zfbimg.hidden && !jdimg.hidden && !wximg.hidden)
    {
        height = 3*CGRectGetHeight(tzfbBtn.frame);
        [line1 setHidden:YES];
        [line2 setHidden:YES];

    }
    else if ((zfbimg.hidden && !jdimg.hidden && !wximg.hidden) || (jdimg.hidden && !zfbimg.hidden && !wximg.hidden) || (wximg.hidden && !zfbimg.hidden && !jdimg.hidden))
    {
        height = CGRectGetHeight(tzfbBtn.frame);
        [line1 setHidden:NO];
        [line2 setHidden:YES];
    }
    else{
        height = CGRectGetHeight(tzfbBtn.frame)*2;
        [line1 setHidden:YES];
        [line2 setHidden:YES];
    }
    if (!zhegai) {
        zhegai = [[UILabel alloc]initWithFrame:CGRectMake(0, zfbBtn.frame.origin.y+CGRectGetHeight(whiteView.frame)-height-0.5, WYMWITH, height)];
        zhegai.backgroundColor = [UIColor whiteColor];
    }
    
    [zhegai setFrame:CGRectMake(0, zfbBtn.frame.origin.y+CGRectGetHeight(tzfbBtn.frame)*3-height, WYMWITH, height)];
    [whiteView addSubview:zhegai];

//    if (jdimg.hidden == YES && zfbimg.hidden==YES && wximg.hidden == YES) {
//        UILabel *zhegai = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMinY(twxBtn.frame)-3, WYMWITH, 50)];
//        zhegai.text = @"";
//        zhegai.font = [UIFont systemFontOfSize:14];
//        zhegai.textAlignment = NSTextAlignmentCenter;
//        zhegai.backgroundColor = QBB_GRAY_COLOR;
//        [whiteView addSubview:zhegai];
//    }
    //上架前处理
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSNumber *flag = [user objectForKey:@"user_show_pay"];
    if ([flag intValue] == 0) {
        for (UIButton *btn in _btns) {
            btn.selected = NO;
        }
    }
}
@end
